import cache from '../config/redis.js';

// 测试Redis模糊查询功能
async function testRedisSearch() {
  try {
    console.log('测试Redis模糊查询功能...');

    // 设置一些测试缓存
    await cache.set('user:1', { name: '张三' });
    await cache.set('user:2', { name: '李四' });
    await cache.set('user:3', { name: '王五' });
    await cache.set('product:1', { name: '手机' });
    await cache.set('product:2', { name: '电脑' });

    console.log('设置测试缓存完成');

    // 测试模糊查询
    const userKeys = await cache.search('user:*');
    console.log('匹配user:*的键:', userKeys);

    const productKeys = await cache.search('product:*');
    console.log('匹配product:*的键:', productKeys);

    const allKeys = await cache.search('*');
    console.log('匹配所有键:*的键数量:', allKeys.length);
    console.log('所有键:', allKeys);

  } catch (err) {
    console.error('Redis测试错误:', err);
  }
}

testRedisSearch();